home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Xconq 7.1.0 / src / xconq-7.1.0 / kernel / cmdline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  19.4 KB  |  686 lines  |  [TEXT/R*ch]

  1. /* Command line parsing for Xconq.
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996
  3.    Stanley T. Shebs.
  4.  
  5. Xconq is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.  See the file COPYING.  */
  9.  
  10. /* This is a command-line parser that may be used in implementations that
  11.    get a command line from somewhere. */
  12.  
  13. /* Command lines get parsed in several stages, since for instance
  14.    the choice of game module will decide which variants are available. */
  15.  
  16. #include "conq.h"
  17. extern void add_library_path PARAMS ((char *path));
  18. #include "cmdline.h"
  19.  
  20. static void version_info PARAMS ((void));
  21. static void general_usage_info PARAMS ((void));
  22. static void game_usage_info PARAMS ((void));
  23. static void unixify_variant_name PARAMS ((char *buf, char *varname));
  24. static void player_usage_info PARAMS ((void));
  25. static void parse_world_option PARAMS ((char *str));
  26. static void parse_realtime_option PARAMS ((char *subopt, char *arg));
  27. static void parse_variant PARAMS ((char *str));
  28. static void add_a_raw_player_spec PARAMS ((char *specstr));
  29.  
  30. /* The startup-settable options. */
  31.  
  32. static int option_alltimeout;
  33. static int option_totalgametime;
  34. static int option_perturntime;
  35. static int option_persidetime;
  36. static int option_add_default_player;
  37.  
  38. static char *default_ai_type = ",mplayer";
  39.  
  40. /* This says whether the command line arguments actually chose a
  41.    specific game to play (as opposed to setting random flags). */
  42.  
  43. static int game_chosen = FALSE;
  44.  
  45. /* The list of asked-for players. */
  46.  
  47. struct raw_spec {
  48.   char *spec;
  49.   struct raw_spec *next;
  50. } *raw_player_specs, *last_raw_player_spec;
  51.  
  52. static char *raw_default_player_spec;
  53.  
  54. /* The list of modules to loaded in addition to the main one. */
  55.  
  56. struct module_spec {
  57.   Module *module;
  58.   struct module_spec *next;
  59. } *extra_modules, *last_extra_module;
  60.  
  61. /* The list of accumulated variant choices. */
  62.  
  63. static Obj *variant_settings;
  64.  
  65. static char *program_name = "";
  66.  
  67. static int help_wanted = FALSE;
  68.  
  69. static int variant_help_wanted = FALSE;
  70.  
  71. static int version_wanted = FALSE;
  72.  
  73. static int had_error = FALSE;
  74.  
  75. /* Set the most basic of defaults on the dynamically-settable options. */
  76.  
  77. /* (need flags to indicate which options were actually used, so variant
  78.    handling can warn about improper use) */
  79.  
  80. void
  81. init_options()
  82. {
  83.     option_add_default_player = TRUE;
  84.     variant_settings = lispnil;
  85. }
  86.  
  87. /* Generic command line parsing.  This is used by several different programs,
  88.    so it just collects info, doesn't process it much.  This is called
  89.    several times, because the validity of some args depends on which
  90.    game modules are loaded and which players are to be in the game,
  91.    and interfaces may need to do some of their own processing in between. */
  92.  
  93. void
  94. parse_command_line(argc, argv, spec)
  95. int argc, spec;
  96. char *argv[];
  97. {
  98.     char *arg, *aispec, tmpspec[100];
  99.     int i, n, numused;
  100.  
  101. /* This macro just checks that a required next argument is actually there. */
  102.  
  103. #define REQUIRE_ONE_ARG  \
  104.   if (i + 1 >= argc) {  \
  105.     fprintf(stderr, "Error: `%s' requires an argument, exiting now\n", argv[i]);  \
  106.     had_error = TRUE;  \
  107.     continue;  \
  108.   }  \
  109.   numused = 2;
  110.  
  111. /* Each of these causes argument parsing to skip over the option if it's
  112.    not the right time to look at it. */
  113.  
  114. #define GENERAL_OPTION if (spec != general_options) continue;
  115. #define VARIANT_OPTION if (spec != variant_options) continue;
  116. #define PLAYER_OPTION  if (spec != player_options)  continue;
  117.  
  118.     /* (should peel off any path stuff) */
  119.     program_name = argv[0];
  120.  
  121.     if (spec == general_options)
  122.       init_options();
  123.  
  124.     for (i = 1; i < argc; ++i) {
  125.     if (argv[i] == NULL || (argv[i])[0] == '\0') {
  126.         /* Already munched, nothing to do. */
  127.     } else if ((argv[i])[0] == '-') {
  128.         arg = argv[i];
  129.         Dprintf("%s\n", arg);
  130.         numused = 1;
  131.         if (strcmp(arg, "-c") == 0) {
  132.         REQUIRE_ONE_ARG;
  133.         GENERAL_OPTION;
  134.         checkpointinterval = atoi(argv[i+1]);
  135.         } else if (strcmp(arg, "-design") == 0) {
  136.         GENERAL_OPTION;
  137. #ifdef DESIGNERS
  138.         allbedesigners = TRUE;
  139. #else
  140.         fprintf(stderr,
  141.             "No designing available, ignoring option `%s'\n", arg);
  142. #endif /* DESIGNERS */
  143.         } else if (strncmp(arg, "-D", 2) == 0) {
  144.         GENERAL_OPTION;
  145. #ifdef DEBUGGING
  146.         Debug = TRUE;
  147.         if (strchr(arg+2, '-'))
  148.           Debug = FALSE;
  149.         if (strchr(arg+2, 'M'))
  150.           DebugM = TRUE;
  151.         if (strchr(arg+2, 'G'))
  152.           DebugG = TRUE;
  153. #else
  154.         fprintf(stderr,
  155.             "No debugging available, ignoring option `%s'\n", arg);
  156. #endif /* DEBUGGING */
  157.         } else if (strncmp(arg, "-e", 2) == 0) {
  158.         REQUIRE_ONE_ARG;
  159.         PLAYER_OPTION;
  160.         n = atoi(argv[i+1]);
  161.         /* A comma indicates that the name of a particular desired
  162.            AI type follows. */
  163.         if (strlen(arg) > 2) {
  164.             aispec = arg + 2;
  165.             if (*aispec != ',') {
  166.             sprintf(tmpspec, ",mplayer%s", aispec);
  167.             aispec = tmpspec;
  168.             }
  169.         } else {
  170.             aispec = default_ai_type;
  171.         }
  172.         while (n-- > 0)
  173.           add_a_raw_player_spec(aispec);
  174.         } else if (strcmp(arg, "-f") == 0) {
  175.         REQUIRE_ONE_ARG;
  176.         GENERAL_OPTION;
  177.         add_a_module(NULL, argv[i+1]); 
  178.         } else if (strcmp(arg, "-g") == 0) {
  179.         REQUIRE_ONE_ARG;
  180.         GENERAL_OPTION;
  181.         add_a_module(copy_string(argv[i+1]), NULL);
  182.         } else if (strcmp(arg, "-h") == 0) {
  183.         REQUIRE_ONE_ARG;
  184.         PLAYER_OPTION;
  185.         fprintf(stderr, "  %s not implemented yet, sorry\n", arg);
  186.         had_error = TRUE;
  187.         } else if (strcmp(arg, "-help") == 0) {
  188.         GENERAL_OPTION;
  189.         help_wanted = TRUE;
  190.         /* Will display help info later. */
  191.         } else if (strcmp(arg, "-join") == 0) {
  192.         REQUIRE_ONE_ARG;
  193.         GENERAL_OPTION;
  194.         fprintf(stderr, "  %s not implemented yet, sorry\n", arg);
  195.         had_error = TRUE;
  196.         } else if (strcmp(arg, "-L") == 0) {
  197.         REQUIRE_ONE_ARG;
  198.         GENERAL_OPTION;
  199.         if (strcmp(argv[i+1], "-") == 0)
  200.           add_library_path(NULL);
  201.         else
  202.           add_library_path(argv[i+1]);
  203.         } else if (strcmp(arg, "-M") == 0) {
  204.         REQUIRE_ONE_ARG;
  205.         VARIANT_OPTION;
  206.         parse_world_option(argv[i+1]);
  207.         } else if (strcmp(arg, "-mail") == 0) {
  208.         GENERAL_OPTION;
  209.         fprintf(stderr, "  %s not implemented yet, sorry\n", arg);
  210.         had_error = TRUE;
  211.         } else if (strcmp(arg, "-r") == 0) {
  212.         PLAYER_OPTION;
  213.         option_add_default_player = FALSE;
  214.         } else if (strcmp(arg, "-R") == 0) {
  215.         REQUIRE_ONE_ARG;
  216.         GENERAL_OPTION;
  217. #ifdef DEBUGGING
  218.         init_xrandom(atoi(argv[i+1]));
  219. #else
  220.         fprintf(stderr,
  221.             "No debugging available, ignoring option `%s'\n", arg);
  222. #endif /* DEBUGGING */
  223.         } else if (strcmp(arg, "-sm") == 0) {
  224.         VARIANT_OPTION;
  225.         push_key_int_binding(&variant_settings, K_SEQUENTIAL, 0);
  226.         } else if (strcmp(arg, "-sq") == 0) {
  227.         VARIANT_OPTION;
  228.         push_key_int_binding(&variant_settings, K_SEQUENTIAL, 1);
  229.         } else if (strncmp(arg, "-t", 2) == 0) {
  230.         REQUIRE_ONE_ARG;
  231.         VARIANT_OPTION;
  232.         parse_realtime_option(arg + 2, argv[i+1]);
  233.         } else if (strncmp(arg, "-v", 2) == 0) {
  234.         VARIANT_OPTION;
  235.         parse_variant(arg + 2);
  236.         } else if (strcmp(arg, "-V") == 0) {
  237.         VARIANT_OPTION;
  238.         push_key_int_binding(&variant_settings, K_SEE_ALL, 1);
  239.         } else if (strcmp(arg, "-w") == 0) {
  240.         GENERAL_OPTION;
  241.         warnings_suppressed = TRUE;
  242.         } else if (strcmp(arg, "-wait") == 0) {
  243.         REQUIRE_ONE_ARG;
  244.         PLAYER_OPTION;
  245.         fprintf(stderr, "  %s not implemented yet, sorry\n", arg);
  246.         had_error = TRUE;
  247.         } else if (strcmp(arg, "-x") == 0) {
  248.         GENERAL_OPTION;
  249.         option_popup_new_game_dialog = TRUE;
  250.         } else if (strcmp(arg, "--help") == 0) {
  251.         GENERAL_OPTION;
  252.         help_wanted = TRUE;
  253.         /* Will display help info later. */
  254.         } else if (strcmp(arg, "--version") == 0) {
  255.         GENERAL_OPTION;
  256.         version_wanted = TRUE;
  257.         } else {
  258.         numused = 0;
  259.         /* Anything unrecognized during the last parse is an error. */
  260.         if (spec >= leftover_options) {
  261.             fprintf(stderr, "Unrecognized option `%s'\n", arg);
  262.             had_error = TRUE;
  263.         }
  264.         }
  265.         if (numused >= 1)
  266.           argv[i] = "";
  267.         if (numused >= 2)
  268.           argv[i+1] = "";
  269.         if (numused >= 1)
  270.           i += (numused - 1);
  271.     } else {
  272.         if (spec == player_options) {
  273.         if (*(argv[i]) == '+' || *(argv[i]) == '@') {
  274.             raw_default_player_spec = argv[i];
  275.         } else {
  276.             add_a_raw_player_spec(argv[i]);
  277.         }
  278.         argv[i] = NULL;
  279.         }
  280.     }
  281.     }
  282.     if (version_wanted) {
  283.     version_info();
  284.     }
  285.     if (had_error || help_wanted || variant_help_wanted) {
  286.     /* If we want to get help about a particular game, have to load it first. */
  287.     if (help_wanted || variant_help_wanted)
  288.       load_all_modules();
  289.     if (had_error || help_wanted)
  290.       general_usage_info();
  291.     if (had_error || help_wanted || variant_help_wanted)
  292.       game_usage_info();
  293.     if (had_error || help_wanted)
  294.       player_usage_info();
  295.     if (help_wanted && mainmodule != NULL) {
  296.         /* (should display other random info about the game here) */
  297.     }
  298.     }
  299.     if (had_error || help_wanted || variant_help_wanted || version_wanted) {
  300.     exit(had_error);
  301.     }
  302. }
  303.  
  304. /* Given a module name and/or filename, add it to the list of modules
  305.    to load. */
  306.  
  307. void
  308. add_a_module(name, filename)
  309. char *name, *filename;
  310. {
  311.     Module *module;
  312.  
  313.     module = get_game_module(name);
  314.     if (module == NULL)
  315.       exit(1);  /* bad error if happens */
  316.     if (filename)
  317.       module->filename = copy_string(filename);
  318.     if (mainmodule == NULL) {
  319.     mainmodule = module;
  320.     } else {
  321.     struct module_spec *extra = (struct module_spec *) xmalloc(sizeof(struct module_spec));
  322.  
  323.     extra->module = module;
  324.     if (extra_modules == NULL)
  325.       extra_modules = extra;
  326.     else
  327.       last_extra_module->next = extra;
  328.     last_extra_module = extra;
  329.     }
  330.     game_chosen = TRUE;
  331. }
  332.  
  333. static void
  334. add_a_raw_player_spec(specstr)
  335. char *specstr;
  336. {
  337.     struct raw_spec *spec =
  338.     (struct raw_spec *) xmalloc (sizeof(struct raw_spec));
  339.  
  340.     spec->spec = copy_string(specstr);
  341.     if (raw_player_specs == NULL)
  342.       raw_player_specs = spec;
  343.     else
  344.       last_raw_player_spec->next = spec;
  345.     last_raw_player_spec = spec;
  346. }
  347.  
  348. static void
  349. version_info()
  350. {
  351.     printf("Xconq (%s) version %s\n", program_name, version_string());
  352. }
  353.  
  354. /* This routine prints out help info about all the possible arguments. */
  355.  
  356. static void
  357. general_usage_info()
  358. {
  359.     printf("Usage:\n\t%s [ -options ... ]\n\n", program_name);
  360.     printf("General options:\n\n");
  361.     printf("    -c n\t\tcheckpoint every <n> turns\n");
  362.     printf("    -f filename\t\trun <filename> as a game\n");
  363.     printf("    -g gamename\t\tfind <gamename> in library and run it\n");
  364.     printf("    -help\t\tdisplay this help info\n");
  365.     printf("    -join <game@host>\tconnect to the given game\n");
  366.     printf("    -L pathname\t\tset <pathname> to be library location\n");
  367.     printf("    -mail\t\tset up game as play-by-email\n");
  368.     printf("    -t mins\t\tlimit each player to <mins> of play time total\n");
  369.     printf("    -tside mins\t\tlimit each player to <mins> of time each turn\n");
  370.     printf("    -tturn mins\t\tlimit each turn to <mins> minutes\n");
  371.     printf("    -w\t\t\tsuppress warnings\n");
  372.     printf("    -design\t\tmake every player a designer\n");
  373.     printf("Long options:\n");
  374.     printf("    --help\t\tdisplay this help info\n");
  375.     printf("    --version\t\tdisplay version info\n");
  376. }
  377.  
  378. /* Describe the available variants for a game. */
  379.  
  380. static void
  381. game_usage_info()
  382. {
  383.     int i, wid, hgt, circumf, lat, lon;
  384.     char *varname = "?", *vartypename = NULL;
  385.     char buf[BUFSIZE];
  386.     Variant *var;
  387.     Obj *vardflt;
  388.  
  389.     printf("\nGame variant options");
  390.     if (mainmodule == NULL) {
  391.     printf(":\n\n    No game loaded, no information available.\n\n");
  392.     return;
  393.     }
  394.     printf(" for \"%s\":\n\n", mainmodule->name);
  395.     if (mainmodule->variants == NULL) {
  396.     printf("    No variants available.\n\n");
  397.     return;
  398.     }
  399.     for (i = 0; mainmodule->variants[i].id != lispnil; ++i) {
  400.     var = &(mainmodule->variants[i]);
  401.     varname = var->name;
  402.     vartypename = c_string(var->id);
  403.     vardflt = var->dflt;
  404.     switch (keyword_code(vartypename)) {
  405.       case K_SEE_ALL:
  406.         printf("    -V\t\t\tmake everything be always seen (default %s)\n",
  407.            (vardflt == lispnil ? "true" :
  408.             (c_number(eval(vardflt)) ? "true" : "false")));
  409.         break;
  410.       case K_SEQUENTIAL:
  411.         printf("    -sm\t\t\tmove simultaneously (default %s)\n",
  412.            (vardflt == lispnil ? "true" :
  413.             (c_number(eval(vardflt)) ? "true" : "false")));
  414.         printf("    -sq\t\t\tmove sequentially (default %s)\n",
  415.            (vardflt == lispnil ? "false" :
  416.             (c_number(eval(vardflt)) ? "false" : "true")));
  417.         break;
  418.       case K_WORLD_SEEN:
  419.         printf("    -v\t\t\tmake the world be seen already (default %s)\n",
  420.            (vardflt == lispnil ? "true" :
  421.             (c_number(eval(vardflt)) ? "true" : "false")));
  422.         break;
  423.       case K_WORLD_SIZE:
  424.         printf("    -M wid[xhgt][Wcircumf][+lat][+lon]\tset world size (default ");
  425.         /* Note that if the game definition sets these values directly using world
  426.            or area forms, this is misleading; but that's the fault of the game
  427.            designer for including both preset values and a variant whose defaults
  428.            don't match those presets. */
  429.         circumf = DEFAULTCIRCUMFERENCE;
  430.         wid = DEFAULTWIDTH;  hgt = DEFAULTHEIGHT;
  431.         lat = lon = 0;
  432.         /* Pick the width and height out of the list. */
  433.         if (vardflt != lispnil) {
  434.         wid = c_number(eval(car(vardflt)));
  435.         vardflt = cdr(vardflt);
  436.         }
  437.         if (vardflt != lispnil) {
  438.         hgt = c_number(eval(car(vardflt)));
  439.         vardflt = cdr(vardflt);
  440.         } else {
  441.         hgt = wid;
  442.         }
  443.         /* Pick up a circumference etc if given. */
  444.         if (vardflt != lispnil) {
  445.         circumf = c_number(eval(car(vardflt)));
  446.         vardflt = cdr(vardflt);
  447.         }
  448.         if (vardflt != lispnil) {
  449.         lat = c_number(eval(car(vardflt)));
  450.         vardflt = cdr(vardflt);
  451.         }
  452.         if (vardflt != lispnil) {
  453.         lon = c_number(eval(car(vardflt)));
  454.         }
  455.         printf("%dx%dW%d", wid, hgt, circumf);
  456.         if (lat != 0 || lon != 0)
  457.           printf("+%d+%d", lat, lon);
  458.         printf(")\n");
  459.         break;
  460.       default:
  461.         unixify_variant_name(buf, varname);
  462.         printf("    -v%s[=value] (default ", buf);
  463.         if (vardflt == lispnil
  464.             || (numberp(vardflt) && c_number(vardflt) == 0)) {
  465.         printf("false");
  466.         } else if (numberp(vardflt) && c_number(vardflt) == 1) {
  467.         printf("true");
  468.         } else {
  469.         sprintlisp(buf, vardflt);
  470.         printf("%s", buf);
  471.         }
  472.         printf(")\n");
  473.         break;
  474.     }
  475.     }
  476. }
  477.  
  478. /* Replace blanks in a variant's name with hyphens, and put the whole
  479.    name in lowercase. */
  480.  
  481. static void
  482. unixify_variant_name(buf, varname)
  483. char *buf, *varname;
  484. {
  485.     int i, slen;
  486.  
  487.     strcpy(buf, varname);
  488.     slen = (int) strlen(buf);
  489.     for (i = 0; i < slen; ++i) {
  490.     if (buf[i] == ' ')
  491.       buf[i] = '-';
  492.     if (isupper(buf[i]))
  493.       buf[i] = tolower(buf[i]);
  494.     }
  495. }
  496.  
  497. static void
  498. player_usage_info()
  499. {
  500.     printf("\nPlayer setup options:\n\n");
  501.     printf("    [[name][,ai][/config]@]host[+advantage]\tadd player\n");
  502.     printf("        ai\t\t= name of AI type or \"ai\" for default type\n");
  503.     printf("        config\t\t= name of config file\n");
  504.     printf("        host\t\t= name of player's host machine or display\n");
  505.     printf("        advantage\t= numerical initial advantage (default 1)\n");
  506.     printf("    -e number[,ai]\tadd <number> computer players\n");
  507.     printf("    -h number[,ai]\tadd <number> human players\n");
  508.     printf("    -r\t\t\tno default player on local display\n");
  509.     printf("    -wait minutes\t\twait time for players to join\n");
  510. }
  511.  
  512. /* Given a string representing world dimensions, extract various components
  513.    and compose a variant setting. */
  514.  
  515. static void
  516. parse_world_option(str)
  517. char *str;
  518. {
  519.     int width, height, circumference;
  520.     char *str2;
  521.     Obj *varval;
  522.  
  523.     width = atoi(str);
  524.     str2 = strchr(str, 'x');
  525.     if (str2 != NULL) {
  526.     height = atoi(str2 + 1);
  527.     } else {
  528.     height = width;
  529.     }
  530.     varval = lispnil;
  531.     /* Add a world circumference setting if present. */
  532.     str2 = strchr(str, 'W');
  533.     if (str2 != NULL) {
  534.     circumference = atoi(str2 + 1);
  535.     if (circumference > 0)
  536.       varval = cons(new_number(circumference), varval);
  537.     else
  538.       fprintf(stderr, "Requested circumference is bad, ignoring\n");
  539.     }
  540.     varval = cons(new_number(width), cons(new_number(height), varval));
  541.     /* Glue onto the list of variant_settings. */
  542.     push_key_cdr_binding(&variant_settings, K_WORLD_SIZE, varval);
  543. }
  544.  
  545. static void
  546. parse_realtime_option(subopt, arg)
  547. char *subopt, *arg;
  548. {
  549.     if (strcmp(subopt, "-timeout") == 0) {
  550.     option_alltimeout = 60 * atoi(arg);
  551.     } else if (strcmp(subopt, "-tgame") == 0) {
  552.     option_totalgametime = 60 * atoi(arg);
  553.     } else if (strcmp(subopt, "-tside") == 0) {
  554.     option_persidetime = 60 * atoi(arg);
  555.     } else if (strcmp(subopt, "-tturn") == 0) {
  556.     option_perturntime = 60 * atoi(arg);
  557.     } else {
  558.         /* usage? */
  559.     }
  560. }
  561.  
  562. /* Given a variant, turn it into a list "(name val)". */
  563.  
  564. static void
  565. parse_variant(str)
  566. char *str;
  567. {
  568.     char *varname = NULL, *str2;
  569.     Obj *varval = lispnil;
  570.  
  571.     if (strcmp(str, "") == 0) {
  572.     push_key_int_binding(&variant_settings, K_WORLD_SEEN, 1);
  573.     } else if (strcmp(str, "help") == 0) {
  574.     variant_help_wanted = TRUE;
  575.     } else {
  576.     str2 = strchr(str, '=');
  577.     if (str2 != NULL && str2 != str) {
  578.         /* (should interp val as string or number) */
  579.         varval = new_number(atoi(str2 + 1));
  580.         varname = copy_string(str);
  581.         varname[str2 - str] = '\0';
  582.     } else {
  583.         /* Assume varname by itself means "enable" (set to value of 1). */
  584.         varname = str;
  585.         varval = new_number(1);
  586.     }
  587.     if (varname)
  588.       push_binding(&variant_settings, intern_symbol(varname), varval);
  589.     }
  590. }
  591.  
  592. /* Load all the game modules that were asked for on cmd line. */
  593.  
  594. void
  595. load_all_modules()
  596. {
  597.     struct module_spec *extra;
  598.  
  599.     if (mainmodule != NULL) {
  600.     load_game_module(mainmodule, TRUE);
  601.     for (extra = extra_modules; extra != NULL; extra = extra->next) {
  602.         load_game_module(extra->module, TRUE);
  603.     }
  604.     } else {
  605.     /* If we've got absolutely no files to load, the standard game is
  606.        the one to go for.  It will direct the remainder of random gen. */
  607.     load_default_game();
  608.     }
  609. }
  610.  
  611. /* Set module variants from command line options. */
  612.  
  613. void
  614. set_variants_from_options()
  615. {
  616.     do_module_variants(mainmodule, variant_settings);
  617. }
  618.  
  619. /* Set player characteristics from command-line options. */
  620.  
  621. void
  622. set_players_from_options()
  623. {
  624.     int mergespecs;
  625.     Player *player;
  626.     struct raw_spec *spec;
  627.  
  628.     player = NULL;
  629.     /* Assume that if any players exist already, then this is a restored
  630.        game of some sort, and merge instead of adding new players. */
  631.     mergespecs = (numplayers > 0);
  632.     if (mergespecs)
  633.       player = playerlist;
  634.     /* Add the default player. */
  635.     if (raw_player_specs == NULL || option_add_default_player) {
  636.     if (!mergespecs)
  637.       player = add_default_player();
  638.     parse_player_spec(player, raw_default_player_spec);
  639.     canonicalize_player(player);
  640.     player = player->next;
  641.     }
  642.     /* Add the explicitly listed players. */
  643.     for (spec = raw_player_specs; spec != NULL; spec = spec->next) {
  644.     if (mergespecs) {
  645.         if (player == NULL) {
  646.         fprintf(stderr, "Excess player spec \"%s\", ignoring\n",
  647.             spec->spec);
  648.         continue;
  649.         }
  650.     } else {
  651.         player = add_player();
  652.     }
  653.     parse_player_spec(player, spec->spec);
  654.     canonicalize_player(player);
  655.     player = player->next;
  656.     }
  657. }
  658.  
  659. /* This is not, strictly speaking, part of command line processing,
  660.    but command-line programs are also the ones for which stdio is useful. */
  661.  
  662. void
  663. print_instructions()
  664. {
  665.     Obj *instructions = mainmodule->instructions, *rest;
  666.  
  667.     printf("\n");
  668.     if (instructions != lispnil) {
  669.     if (stringp(instructions)) {
  670.         printf("%s\n", c_string(instructions));
  671.     } else if (consp(instructions)) {
  672.         for (rest = instructions; rest != lispnil; rest = cdr(rest)) {
  673.         if (stringp(car(rest))) {
  674.             printf("%s\n", c_string(car(rest)));
  675.         } else {
  676.             /* (should probably warn about this case too) */
  677.         }
  678.         }
  679.     } else {
  680.         run_warning("Instructions are of wrong type");
  681.     }
  682.     } else {
  683.     printf("(no instructions supplied)\n");
  684.     }
  685. }
  686.